%funciones pseudo-trapezoidales de salida
%notar que hay 2 grupos, ya que hay diferentes escalas (intensidad y
%voltaje)

posB = zeros(7,1);
posB(1) = [-0.3,-0.3,-0.23,-0.2];
posB(2) = [-0.23,-0.2,-0.15,-0.1];
posB(3) = [-0.15,-0.1,-0.03,0.0];
posB(4) = [-0.03,0.0,0.0,10];
posB(5) = [0,10,60,80];
posB(6) = [60,80,140,160];
posB(7) = [140,160,220,220];

tmin = -0.3;
tmax = 0;
step = 0.025;

npart = (tmax-tmin)/step;

ntrapleft = 4;
B1 = zeros(ntrapleft,npart);
i = 1;
h = 1; %normalizo el set
for x=tmin:step:tmax
   for j=1:ntrapleft
       a = posB(j,1);
       b = posB(j,2);
       c = posB(j,3);
       d = posB(j,4);
       if(x>=a||x<b)
           B1(i,j) = (x-a)/(b-a);
       else
           if(x>=b&&x<c)
               B1(i,j) = h;
           else
               if(x>=c&&x<d)
                   B1(i,j) =  (x-c)/(d-c);
               else
                   B1(i,j) = 0;
               end
           end
       end
   end
   i = i+1;
end

tmin = 0;
tmax = 220;
step = 20;

npart = (tmax-tmin)/step;

ntrapright = 4;
B2 = zeros(ntrapright,npart);
h = 1; %normalizo el set
for x=tmin:step:tmax
   for j=ntrapleft:ntrapright
       a = posB(j,1);
       b = posB(j,2);
       c = posB(j,3);
       d = posB(j,4);
       if(x>=a||x<b)
           B2(i,j) = (x-a)/(b-a);
       else
           if(x>=b&&x<c)
               B2(i,j) = h;
           else
               if(x>=c&&x<d)
                   B2(i,j) =  (x-c)/(d-c);
               else
                   B2(i,j) = 0;
               end
           end
       end
   end
end

B = [B1,B2];
